from django.shortcuts import render
from rest_framework.generics import CreateAPIView, ListAPIView, DestroyAPIView, UpdateAPIView
from rest_framework.permissions import IsAuthenticated

from money import serializers
from money.models import Money


class MoneyYearAdd(CreateAPIView):
    """增加年份"""
    serializer_class = serializers.MoneyYearAddSerializer
    permission_classes = [IsAuthenticated]


class YearListLoad(ListAPIView):
    """获取年份列表"""
    serializer_class = serializers.YearListLoadSerializer
    permission_classes = [IsAuthenticated]
    pagination_class = None

    def get_queryset(self):
        user_id = self.kwargs['user_id']
        return Money.objects.filter(users_id=user_id)


class YearDelete(DestroyAPIView):
    """
    删除年份
    """
    serializer_class = serializers.YearDeleteDeleteSerializer
    permission_classes = [IsAuthenticated]

    def get_queryset(self):
        year_id = self.kwargs['pk']
        return Money.objects.filter(id=year_id)


class AddMoney(UpdateAPIView):
    """
    提交添加资金
    """
    serializer_class = serializers.AddMoneySerializer
    permission_classes = [IsAuthenticated]

    def get_queryset(self):
        year_id = self.kwargs['pk']
        print(year_id)
        return Money.objects.filter(id=year_id)


class YearMMoney(UpdateAPIView):
    """
    提交年末资金
    """
    serializer_class = serializers.YearMMoneySerializer
    permission_classes = [IsAuthenticated]

    def get_queryset(self):
        year_id = self.kwargs['pk']
        return Money.objects.filter(id=year_id)


class OutMoney(UpdateAPIView):
    """
    提交取出资金
    """
    serializer_class = serializers.OutMoneySerializer
    permission_classes = [IsAuthenticated]

    def get_queryset(self):
        year_id = self.kwargs['pk']
        return Money.objects.filter(id=year_id)